package com.ruoyi.web.controller.bus.controller;

import com.ruoyi.bus.domain.BusException;
import com.ruoyi.bus.service.IBusExceptionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@Controller
@RequestMapping("/bus/exception")
public class BusExceptionController extends BaseController
{
    private String prefix = "bus/exception";

    @Autowired
    private IBusExceptionService busExceptionService;

    @RequiresPermissions("bus:exception:view")
    @GetMapping()
    public String exception()
    {
        return prefix + "/exception";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("bus:exception:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusException busException)
    {
        startPage();
        List<BusException> list = busExceptionService.selectBusExceptionList(busException);
        return getDataTable(list);
    }



    @RequestMapping("/list/{monitorId}")
    @ResponseBody
    public TableDataInfo listById(@PathVariable("monitorId") Long monitorId ,BusException busException)
    {
//        Long monitorId1 = Long.parseLong(request.getParameter("monitorId"));
//        busException.setMonitorId("monitorId");
//        startPage();
        List<BusException> list = busExceptionService.selectBusExceptionByMonitorId(monitorId);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("bus:exception:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusException busException)
    {
        List<BusException> list = busExceptionService.selectBusExceptionList(busException);
        ExcelUtil<BusException> util = new ExcelUtil<BusException>(BusException.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }




    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("bus:exception:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusException busException)
    {
        return toAjax(busExceptionService.insertBusException(busException));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusException busException = busExceptionService.selectBusExceptionById(id);
        mmap.put("busException", busException);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("bus:exception:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusException busException)
    {
        return toAjax(busExceptionService.updateBusException(busException));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("bus:exception:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busExceptionService.deleteBusExceptionByIds(ids));
    }
}
